package com.group9.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyIntercptor implements HandlerInterceptor {

    // true -> 放行  false  拦截
    // preHandle -》 控制器方法 -》 posthandler-》afterCompletion
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("============Interceptor================");

        HttpSession session = request.getSession();
        String user = (String) session.getAttribute("username");
//        if(null == user) {
//            response.sendRedirect("/springboot/login.jsp");
//            return false;
//
//        }

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
